package com.heatmap;

public class PaintHeatMap {
	public static final int MAX_X = 10;
	public static final int MAX_Y = 10;

	public static int[][][] heatMap = new int[MAX_X][MAX_Y][1];;

	public static void main(String[] args) {//this method will compose random input and will pass it to paintHeatMap method for rendering
		
		for(int masteLoop = 0; masteLoop < 3; masteLoop++){//will run the paintHeatMap method 3 times 
			int[][][] x = new int[MAX_X][MAX_Y][1];
			for (int i = 0 ; i< MAX_X; i++){//compose a random input
				for (int j = 0 ; j< MAX_Y; j++){
					x[i][j][0] = 0;

					if(((int)(Math.random() *10))%3 == 0){
						int heatVal = (int)(Math.random() * 10);
						x[i][j][0] = heatVal;
					}
				}
			}

			System.out.println("\nPaint Count: "+masteLoop);
			paintHeatMap(x);
		}
	
	}

	private static void paintHeatMap(int[][][] newVal){//Will paint the changed pixels by iterating over each value. Code complexity will be O(n2)
		for (int i = 0 ; i< MAX_X; i++){//paint the pixels which are changed, iterate over all the array
			for (int j = 0 ; j< MAX_Y; j++){

				if(newVal[i][j][0] != heatMap[i][j][0]){//overwite the heat value which has changed
					heatMap[i][j][0] = newVal[i][j][0];
				}

				System.out.print("["+i+","+j+","+heatMap[i][j][0]+"]");
			}
			System.out.println();
			
		}

	}

}
